<template>
    <div class="listDiv">
        <div class="searchDiv">
            <el-select v-model="obj.req.state" placeholder="全部状态" class="search_select" style="margin-left: 0;" clearable>
                <el-option v-for="(item,index) in globalData.stateTypeAry" :key="index" :label="item.text" :value="item.value" />
            </el-select>
            <el-select v-model="obj.req.type" placeholder="全部类别" class="search_select" clearable>
                <el-option v-for="(item,index) in globalData.staffTypeList" :key="index" :label="item.text" :value="item.value" />
            </el-select>
            <el-input clearable placeholder="匹配名称/手机" v-model="obj.req.key" class="search_key" />
            <span class="btn search" @click="init">搜索</span>
            <span class="btn refresh" @click="obj.req.currentpage=1;init()"></span>
            <div class="searchRight">
                <span class="btn add" @click="add">添加员工</span>
            </div>
        </div>
        <div class="flex-row-center mb5">
            <span class="mini-size mr5">考勤合格率:</span>
            <span class="mini-size mr10">{{obj.qualified_sign0||0}}%</span>
            <el-input-number clearable placeholder="考勤合格率" v-model="obj.qualified_sign" :min="0" :max="100"  />
            <span class="btn add ml5" @click="qualified_sign_design">修改</span>
        </div>
        <div class="table_box"><div class="table_" id="tb">
            <ul class="head">
                <li class="">员工姓名</li>
                <li class="wcen">电话</li>
                <li class="wcen">类别</li>
                <li class="">职务</li>
                <li class="wcen">考勤达成率</li>
                <li class="wcen">工单完成率</li>
                <li class="wcen">正常/停用</li>
                <li class="mw150 wcen">操作</li>
            </ul>
            <div class="body">
                <ul v-for="x in obj.ary" :key="x">
                    <li class="">{{x.name}}</li>
                    <li class="wcen">{{x.mobile}}</li>
                    <li class="wcen">{{proxy.$utils.find(globalData.staffTypeList, x.type)}}</li>
                    <li class="">{{x.job}}</li>
                    <li class="wcen base-color"><u class="pointer" @click="sign(x)">{{parseFloat(x.sign).toFixed(2)}}%</u></li>
                    <li class="wcen">{{parseFloat(x.works).toFixed(2)}}%</li>
                    <li class="wcen">
                        <el-switch v-model="x.state" size="small" :validate-event="false" @change="setstate(x)"
                            active-text="" inactive-text=""
                            active-value="1" inactive-value="0">
                        </el-switch>
                    </li>
                    <li class="mw150 wcen">
                        <el-button class="edit_btn mr10" type="success" @click="edit(x)">修改</el-button>
                        <DelConfirm class="" @yesClick="del(x)" />
                    </li>
                </ul>
            </div>
        </div>
        </div><Pager :value="obj.req" :init="init" />

        <el-dialog v-model="obj.drawer.design" :title="obj.drawer.designTitle" width="1000px" :close-on-click-modal="false" :destroy-on-close="true">
            <router-view @close="obj.drawer.design = false" @init="init" />
        </el-dialog>
        <el-dialog v-model="obj.drawer.sign" :title="obj.drawer.signTitle" width="1000px" :close-on-click-modal="false" :destroy-on-close="true">
            <Sign :property_id="obj.drawer.property_id" @close="obj.drawer.sign = false" @init="init" />
        </el-dialog>
    </div>
</template>

<script setup>
    import { reactive, getCurrentInstance, ref, toRefs, provide, computed } from 'vue'
    import Pager from '@/components/pager.vue'
    import DelConfirm from '@/components/del_confirm.vue'
    import Sign from './sign.vue'
    let { proxy } = getCurrentInstance()

    let obj = reactive({
        drawer: {
            property_id:"",
            design: false,
            designTitle: "",
            sign: false,
            signTitle:"",
        },
        ary: [],
        req: {
            currentpage: 1,
            pagesize: 10,
            count: 0,
            key: "",
            state:"",
            type:"",
        },
        qualified_sign0: 0,
        qualified_sign: 0,
    });
    let init = () => {
        proxy.$ajax({
            url: '/property/list',
            data: obj.req,
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                obj.ary = d.msg.list
                obj.req.count = d.msg.count
            }
        }).catch(() => { })

        qualified_sign_get()
    }

    let qualified_sign_get = ()=>{
        proxy.$ajax({
            url: '/material/qualified_sign_get',
            data: {},
            bfLoading: true
        }).then(d => {
            if(d.success){
                obj.qualified_sign0 = +d.msg||0
                obj.qualified_sign =  +d.msg||0
            }
        }).catch(() => { })
    }

    let qualified_sign_design = ()=>{
        if(obj.qualified_sign===''){
            proxy.elMessageMixin('请输入合格率', 'error')
            return
        }
        proxy.$ajax({
            url: '/material/qualified_sign_design',
            data: {qualified_sign:obj.qualified_sign},
            bfLoading: true
        }).then(d => {
            if(d.success){
                proxy.elMessageMixin("修改成功", 'success')
                qualified_sign_get()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }

    let editId = ref(0)
    provide("id", editId); //不能加.value
    let add = () => {
        obj.drawer.design = true
        obj.drawer.designTitle = "添加员工"
        editId.value = 0;
    }
    let edit = x => {
        obj.drawer.design = true
        obj.drawer.designTitle = "修改员工"
        editId.value = x.property_id;
    }
    let sign = x => {
        obj.drawer.sign = true
        obj.drawer.signTitle = `${x.name} 员工考勤`
        obj.drawer.property_id = x.property_id;
    }

    let setstate = x => {
        proxy.$ajax({
            url: '/property/setstate',
            data: { property_id: x.property_id },
            bfLoading: true
        }).then(d => {
            if(d.success){
                proxy.elMessageMixin("状态变更成功", 'success')
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }
    let del = x => {
        proxy.$ajax({
            url: '/property/delete',
            data: { id: x.property_id },
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                proxy.elMessageMixin("删除成功", 'success')
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }
</script>

<style scoped>
    ::-webkit-scrollbar { width:10px; background-color: #FFFFFF; }
    .search_select { margin-left: 5px; width:100px!important; }
    .search_key { width:160px!important; }
    #tb ul li.li2 { width: 60px; }
    #tb ul li.li3 { width: 75px; }
    #tb ul li.li4 { width: 75px; }
    #tb ul li.li4 u { cursor: pointer; }
    #tb ul li.li5 { width: 75px; }
</style>